//
//  GameOverViewController.m
//  2048-for-ios
//
//  Created by Martin Hadzhiyski on 4/8/14.
//  Copyright (c) 2014 IOTrainingCamp. All rights reserved.
//

#import "GameOverViewController.h"
#import "config.h"
#import "IOTCGame.h"
#import<Social/Social.h>

@interface GameOverViewController ()
@property (weak, nonatomic) IBOutlet UIButton *tryAgainButton;
@property (weak, nonatomic) IBOutlet UIButton *facebookButton;

@end

@implementation GameOverViewController

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.view.alpha = 0.4;
    self.reasonLabel.font = [UIFont systemFontOfSize:kNumberFontSize];
    self.tryAgainButton.titleLabel.font = [UIFont systemFontOfSize:kLabelFontSize];
    self.facebookButton.titleLabel.font = [UIFont systemFontOfSize:kLabelFontSize];
    
    switch (self.gameEndReason) {
        case LOOSE:
            self.reasonLabel.text = @"You loose :(";
            break;
        case WIN:
            self.reasonLabel.text = @"You win : )";
            break;
        default:
            break;
    }
    // Do any additional setup after loading the view from its nib.
}

- (IBAction)startNewGame:(id)sender {
    IOTCGame* game = [IOTCGame sharedInstance];
    [game loadANewGameWithSize:game.size];
    [self.view removeFromSuperview];
    [self removeFromParentViewController];
}

- (IBAction)shareInFacebook:(id)sender {
    NSLog(@"sharing");
            SLComposeViewController *controller = [SLComposeViewController composeViewControllerForServiceType:SLServiceTypeFacebook];
            
            switch (self.gameEndReason) {
                case LOOSE:
                    [controller setInitialText: [NSString stringWithFormat: @"I have just made %lu points on 2048!", [[IOTCGame sharedInstance] score]]];
                    break;
                case WIN:
                    [controller setInitialText: [NSString stringWithFormat: @"I have just made %lu points on 2048! And I won!", [[IOTCGame sharedInstance] score]]];
                    break;
                default:
                    break;
            }
            
           
    [self presentViewController:controller animated:YES completion:^(){
                    [self.view removeFromSuperview];
                    [self removeFromParentViewController];
    }];
    

    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
